/*
 * Copyright (c) 2016 moondev.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.moondev.moonlog.example.moonlog.monitor.controller;

import java.util.HashMap;
import java.util.Map;

import cn.moondev.moonlog.example.moonlog.monitor.service.SqlMonitorService;
import cn.moondev.moonlog.example.moonlog.monitor.entity.SqlMonitor;
import cn.moondev.moonlog.example.moonlog.monitor.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SqlMonitorController {
	
	@Autowired
	SqlMonitorService sqlMonitorService;

	@RequestMapping(value="/monitor/Sql/list", method=RequestMethod.GET)
    @ResponseBody
	public Map<String,Object> list(String sys,int index,int size,String start,String end,String date) {
		Map<String,Object> result = new HashMap<String,Object>();
		try {
			Page<SqlMonitor> page = sqlMonitorService.list(sys, index, size, start, end, date);
			result.put("code", "200");
			result.put("total", page.getTotalCount());
			result.put("page", page.getTotalPages());
			result.put("data", page.getResult());
		}catch(Exception e) {
			result.put("code", "500");
			result.put("msg", "系统异常，请稍后再试");
		}
		return result;
	}
}
